// pages/rescue/list/list.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		type: true
	},
	onLoad: function(options) {
		console.log(options)
		wx.getStorage({
			key: 'uid',
			success: (e) => {
				this.setData({
					uid: e.data.uid
				})
			}
		})
		this.setData({
			data: options
		})
	},
	type() {
		this.setData({
			type: !(this.data.type)
		})
	},
	vip() {
		let a=this.data.data.id
		a=parseFloat(a)+1
		if (this.data.type) {
			if (this.data.name != undefined && this.data.card != undefined && this.data.moubile != undefined && this.data.cardName !=
				undefined) {
				if (this.data.data.id != 1) {
					let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
					let x = this.data.data.lng;
					let y = this.data.data.lat;
					let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
					let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
					let lngs = z * Math.cos(theta) + 0.0065;
					let lats = z * Math.sin(theta) + 0.006;
					wx.request({
						url: getApp().globalData.http2+'action=dadianOrder&userid=' + this.data.uid + '&CarType=' + this
							.data.name +
							'&carNumber=' + this.data.card + '&mobile=' + this.data.moubile + '&uname=' + this.data.cardName +
							'&prices=50&addr=' + this.data.data.map +
							'&Longitude=' + lats + '&Latitude=' + lngs + '&jytype=' + a,
						success: (e) => {
							console.log(e)
							wx.navigateTo({
								url: '../../Vip/deal/deal?orderCode=' + e.data.data.orderCode + '&totalprice=' + e.data.data.totalprice
							})
						}
					})
				} else {
					let x_pi = 3.14159265358979324 * 3000.0 / 180.0;
					let x1 = this.data.data.lng;
					let y1 = this.data.data.lat;
					let x = this.data.data.dlng;
					let y = this.data.data.dlat;
					let z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
					let z1 = Math.sqrt(x1 * x1 + y1 * y1) + 0.00002 * Math.sin(y * x_pi);
					let theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
					let lngs = z * Math.cos(theta) + 0.0065;
					let lats = z * Math.sin(theta) + 0.006;
					let lngs1 = z1 * Math.cos(theta) + 0.0065;
					let lats1 = z1 * Math.sin(theta) + 0.006;
					wx.request({
						url: getApp().globalData.http2+'action=tuocheOrder&userid=' + this.data.uid + '&CarType=' + this
							.data.name +
							'&carNumber=' + this.data.card + '&mobile=' + this.data.moubile + '&uname=' + this.data.cardName +
							'&prices=' + this.data.data.monkey + '&addr=' + this.data.data.map +
							'&Longitude=' + lats + '&Latitude=' + lngs + '&jytype=' + this.data.data.id + '&TAddress=' +
							this.data.data.destination + '&TLongitude=' + lngs1 + '&TLatitude=' + lats1 + '&millions=' + this.data.data.length,
						success: (e) => {
							console.log(e)
							wx.navigateTo({
								url: '../../Vip/deal/deal?orderCode=' + e.data.data.orderCode + '&totalprice=' + e.data.data.totalprice
							})
						}
					})
				}
			} else {
				wx.showToast({
					icon: "none",
					title: "请正确填写信息"
				})
			}
		} else {
			wx.showToast({
				icon: 'none',
				title: '请同意路救服务协议'
			})
		}



	},
	name(e) {
		this.setData({
			name: e.detail.value
		})
	},
	card(e) {
		this.setData({
			card: e.detail.value
		})
	},
	cardName(e) {
		this.setData({
			cardName: e.detail.value
		})
	},
	moubile(e) {
		this.setData({
			moubile: e.detail.value
		})
	},
})
